public class Task2 {
    public static void main(String[] args) {
        // 创建String类对象
        String originalString = "A dog is a kind of animal";

        // 使用String对象生成StringBuffer对象
        StringBuffer stringBuffer = new StringBuffer(originalString);

        // 把"dog"替换成"cat"
        int startIndex = stringBuffer.indexOf("dog");
        if (startIndex != -1) {
            stringBuffer.replace(startIndex, startIndex + "dog".length(), "cat");
        }

        // 输出结果
        System.out.println("原始字符串: " + originalString);
        System.out.println("替换后的StringBuffer: " + stringBuffer.toString());
    }
}
